<template>
	<view class="container">
		<view class="img_container">
			<image :src="isavator?  form.avatar :'../../static/img/myCenter/girl.png'" mode="" ></image>
			<image src="../../static/img/camera.png" mode="" class="camera"></image>
		</view>
		<view class="profile_part">
			<view class="name">
				昵称
			</view>
			<view class="real_name">
				<view class="">
					<input type="text" placeholder="昵称" v-model="form.nickname"/>
				</view>
				<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
			</view>
		</view>
		<view class="profile_part">
			<view class="name">
				性别
			</view>
			<view class="real_name">
				<picker :value="index" :range="sexs" @change="sexchange">
					<view>{{sexs[index]}} </view>
				</picker>
				<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
			</view>
		</view>
		<view class="profile_part">
			<view class="name">
				年龄
			</view>
			<view class="real_name">
				<view class="">
					<input type="number" placeholder="年龄" v-model="form.age"/>
				</view>
				<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
			</view>
		</view>
		<view class="profile_part">
			<view class="name">
				城市
			</view>
			<view class="real_name">
				<view class="">
					<input type="text" placeholder="输入所在城市" v-model="form.city"/>
				</view>
				<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
			</view>
		</view>
		<view class="profile_part">
			<view class="name">
				学历
			</view>
			<view class="real_name">
				<picker :value="eindex" :range="educations" @change="educhange">
					<view>{{educations[eindex]}} </view>
				</picker>
				<image src="../../static/img/myCenter/arrowright.png" mode=""></image>
			</view>
		</view>
		<Blank></Blank>
		<!-- 教育展示 -->
		<view class="experience_part">
			<view class="title">
				教育经历
			</view> 
			<view class="e_list" v-for="(item,index) in educationHistory" :key="index">
				<view>
					<image src="../../static/img/detailInfo/edc_ico1.png" mode=""></image>
					<text>学校</text>
					<text>{{item.school}}</text>
				</view>
				<view>
					<image src="../../static/img/detailInfo/edc_ico2.png" mode=""></image>
					<text>入学时间</text>
					<text>{{item.beginTime}}</text>
				</view>
				<view>
					<image src="../../static/img/detailInfo/edc_ico3.png" mode=""></image>
					<text>毕业时间</text>
					<text>{{item.endTime}}</text>
				</view>
				<view>
					<image src="../../static/img/detailInfo/edc_ico4.png" mode=""></image>
					<text>所学专业</text>
					<text>{{item.major}}</text>
				</view>
				<button type="default" @click="del_education(item.id)">删除</button>
			</view>
			<view class="content" v-if="1">
				<navigator url="/pages/educationExperience/educationExperience">
				<view class="add_part">
					<image src="../../static/img/plus.png" mode=""></image>
					点击添加
				</view>
				</navigator>
				<view class="">
					请添加你的教育经历，毕业学校等信息
				</view>
			</view>
			
		</view>
        <Blank></Blank>
		<view class="experience_part">
			<view class="title">
				工作经历
			</view>
			<view class="e_list" v-for="(item,index) in companyHistory" :key="index">
				<view>
					<image src="../../static/img/personal/personal_9.png" mode=""></image>
					<text>工作类型</text>
					<text>{{item.jobType}}</text>
				</view>
				<view>
					<image src="../../static/img/personal/personal_10.png" mode=""></image>
					<text>工作职位</text>
					<text>{{item.job}}</text>
				</view>
				<view>
					<image src="../../static/img/personal/personal_7.png" mode=""></image>
					<text>开始时间</text>
					<text>{{item.beginTime}}</text>
				</view>
				<view>
					<image src="../../static/img/personal/personal_8.png" mode=""></image>
					<text>结束时间</text>
					<text>{{item.endTime}}</text>
				</view>
				<view>
					<image src="../../static/img/personal/personal_11.png" mode=""></image>
					<text>公司名称</text>
					<text>{{item.company }}</text>
				</view>
				<view>
					<image src="../../static/img/personal/personal_12.png" mode=""></image>
					<text>工作城市</text>
					<text>{{item.city }}</text>
				</view>
				<view>
					<image src="../../static/img/personal/personal_16.png" mode=""></image>
					<text>工作描述</text>
					<text>{{item.remark }}</text>
				</view>
				<button type="default" @click="del_company(item.id)">删除</button>
			</view>
			<view class="content">
				<navigator url="/pages/workExperience/workExperience">
				<view class="add_part">
					<image src="../../static/img/plus.png" mode=""></image>
					点击添加
				</view>
				</navigator>
				<view class="">
					请添加你的工作类型，工作职位等信息
				</view>
			</view>
			
		</view>
		<Blank></Blank>
		<view class="experience_part">
			<view class="title">
				个人标签
			</view>
			<view>
				<text>{{userinfo.label}}</text>
			</view>
			<view class="content">
				<navigator url="/pages/jobTags/jobTags">
				<view class="add_part">
					<image src="../../static/img/plus.png" mode=""></image>
					点击添加
				</view>
				</navigator>
				<view class="">
					请添加你的职场亮点，工作特长等信息
				</view>
			</view>
			
		</view>
		<view class="car_image">
			<view class="tip">
				<view class="">
					个人照片
				</view>
				<view class="no_require">
					(不必须)
				</view>
				
			</view>
			<view class="package_img" @click="upload">
					<image :src='form.avatar?  form.avatar : imgsFile' mode=""></image>
			</view>
		</view>
		<HandleBtn btnName="保存" @click.native="edituserinfo()" class="confirm_btn"></HandleBtn>
	
			
	</view>
	
</template>

<script>
	import Blank from "../../components/blank.vue"
	import HandleBtn from "../../components/handleBtn.vue"
	export default {
		components: {
			Blank,
			HandleBtn,
		},
		data() {
			return {
				imgsFile:require('../../static/img/photo.png'),
				accessToken:null,
				educations: ['本科以上', '专科', '高中'],
				sexs:['未知','男','女'],
				index:0,
				eindex:1,
				userinfo:[],
				educationHistory:[],
				companyHistory:[],
				form:{
					nickname:"",
					sex:"",
					age:"",
					education:"专科",
					avatar:"",
					image:[],
					city:""
				},
				isavator:false,
			}
		},
		created() {
			this.getuserinfo()
			this.geteducationHistory()
			this.getcompanyHistory()
		},
		methods: {
			getuserinfo(){
				this.$utils.requert({url:'personMsg',type:'post'}).then(res=>{
						if(res.code === 1 ){
							if(res.data.avatar){
								this.isavator = true
							}
							this.userinfo = res.data
							this.form.avatar = res.data.avatar
							console.log(this.form.avator)
							this.form.sex = res.data.sex
							this.form.nickname = res.data.nickname
							this.form.education = res.data.education
							this.eindex = res.data.education=="本科以上"?0:(res.data.education=="专科"?1:2)	
							this.form.age = res.data.age
							this.form.city = res.data.city
							if(res.data.sex!=0){
								this.index = res.data.sex
							}else{
								this.index = 1
							}
						}else{    
							this.$utils.showLayer(res.message)
						}
					})
			},
			
			edituserinfo(){
				this.$utils.requert({url:'alterMsg',type:'post',data:this.form}).then(res=>{
						if(res.code === 1 ){
							this.$utils.showLayer(res.message)
							this.userinfo = res.data
						}else{    
							this.$utils.showLayer(res.message)
						}
					})
			},
			geteducationHistory(){
				this.$utils.requert({url:'educationHistory',type:'post'}).then(res=>{
						if(res.code === 1 ){
							// this.$utils.showLayer(res.message)
							this.educationHistory = res.data
						}else{    
							this.$utils.showLayer(res.message)
						}
					})
			},
			getcompanyHistory(){
				this.$utils.requert({url:'companyHistory',type:'post'}).then(res=>{
						if(res.code === 1 ){
							// this.$utils.showLayer(res.message)
							this.companyHistory = res.data
						}else{    
							this.$utils.showLayer(res.message)
						}
					})
			},
			// 教育经历删除
			del_education(id){
				this.$utils.requert({url:'educationDelete',type:'post',data:{'id':id}}).then(res=>{
						if(res.code === 1 ){
							this.$utils.showLayer(res.message)
							this.educationHistory = res.data
						}else{    
							this.$utils.showLayer(res.message)
						}
					})
			},
			// 工作经历删除
			del_company(id){
				this.$utils.requert({url:'companyDelete',type:'post',data:{'id':id}}).then(res=>{
						if(res.code === 1 ){
							this.$utils.showLayer(res.message)
							this.companyHistory = res.data
						}else{    
							this.$utils.showLayer(res.message)
						}
					})
			},
			// 选择
			sexchange(e) {
			    this.index = e.target.value
			    this.form.sex = e.target.value
			},
			educhange(e) {
			    this.eindex = e.target.value
			    this.form.education = this.educations[e.target.value]
			},
			upload(){
				   uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: res=> {
						const file = res.tempFilePaths[0]
						const  token  = uni.getStorageSync('token')
						uni.uploadFile({
							url: this.$utils.domain+'/api/api/uploadImg', //仅为示例，非真实的接口地址
							filePath: file,
							name: 'file',
							header:{
								'accessToken':token
							},
							formData: {
								'type': '1'
							},
							success: (res) => {
								var res = JSON.parse(res.data)
								this.imgsFile = this.form.avatar = res.data.src
							}
						});
					},
					error : function(e){
					 // console.log(e);
					}
				  });
			}
		}
	}
</script>
<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #fff;
	}
</style>
<style scoped>
	.container {
		width: 100%;
		height: 100%;
	}
	.car_image{
		padding:0 24rpx 50rpx;
		box-sizing: border-box;
	}
	.car_image .tip{
		display: flex;
		align-items: center;
		font-size: 32rpx;
		color: #323232;
		margin-bottom: 46rpx;
	}
	.car_image .tip .no_require{
		font-size: 28rpx;
		color: #BBBBBB;
	}
	.car_image .package_img{
		width:200rpx;
		height: 200rpx;
		background-color: #f5f4f6;
		text-align: center;
	}
	.car_image .package_img image{
		width:100%;
		height: 100%;
		/* margin-top: 62rpx */
	}
	.confirm_btn{
		margin-top: 70rpx;
		margin-bottom: 70rpx;
	}
	.img_container{
		text-align: center;
		margin:62rpx 0;
		position: relative;
	}
	.img_container image{
		width: 144rpx;
		height: 144rpx;
		border-radius: 50%;
		}
	.img_container .camera{
		width:50rpx;
		height: 50rpx;
		position: absolute;
		top:80rpx;
		right:300rpx;
	}
	.profile_part{
		padding:48rpx 24rpx;
		box-sizing: border-box;
		border-bottom: 1rpx solid #f6f6f6;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 32rpx;
		color: #363636;
	}
	.profile_part .real_name{
		display: flex;
		align-items: center;
	}
	.profile_part .real_name view{
		margin-right: 10rpx;
	}
	.profile_part .real_name image{
		width: 16rpx;
		height: 28rpx;
		margin-left: 20rpx;
	}
	.profile_part .real_name input {
		text-align: right;
	}
	.experience_part{
		padding: 46rpx 30rpx;
		box-sizing: border-box;
		background-color: #fff;
	}
	.experience_part .title{
		font-size: 32rpx;
		color: #323232;
		margin-bottom: 46rpx;
		
	}
	.experience_part .e_list{
		position: relative;
		background-color: #fff;
		border-radius: 20rpx;
		margin: 20rpx 0rpx;
		border: 1px solid #f6f6f6;
	}
	.experience_part .e_list view{
		display: flex;
		align-items: center;
		margin-left: 30rpx;
		height: 80rpx;
		
	}
	.experience_part .e_list view text{
		font-size: 24rpx;
		margin-left: 20rpx;
	}
	.experience_part .e_list view text{
		width: 30%;
	}
	.experience_part .e_list view image{
		width: 30rpx;
		height: 30rpx;
	}
	.experience_part .e_list  button{
		margin: 0;
		margin-left: auto;
		width: 150rpx;
		font-size: 24rpx;
		border: none;
		position: absolute;
		top: 150rpx;
		right: 30rpx;
		color: #7a7a7a;
		border-radius: 30rpx;
	}
	.experience_part .e_list  button::after{
		border:none;
	}
	.experience_part .content{
		background:rgba(246,246,245,1);
		/* border:1px solid rgba(182,182,182,1); */
		border-radius: 7rpx;
		font-size: 28rpx;
		color: #838282;
		width: 100%;
		height: 186rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		text-align: center;
		
		
	}
	.experience_part .content image{
		width:38rpx;
		height: 38rpx;
	}
		.experience_part .content .add_part{
			color: #FB8408;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-bottom: 20rpx;
		}
	
</style>
